Conditions | 1 |
Paths | 1 |
Total Lines | 139 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | module.exports = function(GedcomX){ |
||
2 | |||
3 | var utils = require('../utils'), |
||
4 | Base = require('../Base'); |
||
5 | |||
6 | /** |
||
7 | * A set of properties for convenience in displaying a summary of a place. |
||
8 | * |
||
9 | * @see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/rs-specification.md#place-display-properties-data-type|GEDCOM X RS Spec} |
||
10 | * |
||
11 | * @class PlaceDisplayProperties |
||
12 | * @extends Base |
||
13 | * @param {Object} [json] |
||
|
|||
14 | */ |
||
15 | var PlaceDisplayProperties = function(json){ |
||
16 | |||
17 | // Protect against forgetting the new keyword when calling the constructor |
||
18 | if(!(this instanceof PlaceDisplayProperties)){ |
||
19 | return new PlaceDisplayProperties(json); |
||
20 | } |
||
21 | |||
22 | // If the given object is already an instance then just return it. DON'T copy it. |
||
23 | if(PlaceDisplayProperties.isInstance(json)){ |
||
24 | return json; |
||
25 | } |
||
26 | |||
27 | this.init(json); |
||
28 | }; |
||
29 | |||
30 | PlaceDisplayProperties.prototype = Object.create(Base.prototype); |
||
31 | |||
32 | PlaceDisplayProperties._gedxClass = PlaceDisplayProperties.prototype._gedxClass = 'GedcomX.PlaceDisplayProperties'; |
||
33 | |||
34 | PlaceDisplayProperties.jsonProps = [ |
||
35 | 'name', |
||
36 | 'fullName', |
||
37 | 'type' |
||
38 | ]; |
||
39 | |||
40 | /** |
||
41 | * Check whether the given object is an instance of this class. |
||
42 | * |
||
43 | * @param {Object} obj |
||
44 | * @returns {Boolean} |
||
45 | */ |
||
46 | PlaceDisplayProperties.isInstance = function(obj){ |
||
47 | return utils.isInstance(obj, this._gedxClass); |
||
48 | }; |
||
49 | |||
50 | /** |
||
51 | * Initialize from JSON |
||
52 | * |
||
53 | * @param {Object} |
||
54 | * @return {PlaceDisplayProperties} this |
||
55 | */ |
||
56 | PlaceDisplayProperties.prototype.init = function(json){ |
||
57 | |||
58 | Base.prototype.init.call(this, json); |
||
59 | |||
60 | if(json){ |
||
61 | this.setName(json.name); |
||
62 | this.setFullName(json.fullName); |
||
63 | this.setType(json.type); |
||
64 | } |
||
65 | return this; |
||
66 | }; |
||
67 | |||
68 | /** |
||
69 | * Set the name |
||
70 | * |
||
71 | * @param {String} name |
||
72 | * @return {PlaceDisplayProperties} this |
||
73 | */ |
||
74 | PlaceDisplayProperties.prototype.setName = function(name){ |
||
75 | this.name = name; |
||
76 | return this; |
||
77 | }; |
||
78 | |||
79 | /** |
||
80 | * Get the name |
||
81 | * |
||
82 | * @return {String} name |
||
83 | */ |
||
84 | PlaceDisplayProperties.prototype.getName = function(){ |
||
85 | return this.name; |
||
86 | }; |
||
87 | |||
88 | /** |
||
89 | * Set the full name |
||
90 | * |
||
91 | * @param {String} fullName |
||
92 | * @return {PlaceDisplayProperties} this |
||
93 | */ |
||
94 | PlaceDisplayProperties.prototype.setFullName = function(fullName){ |
||
95 | this.fullName = fullName; |
||
96 | return this; |
||
97 | }; |
||
98 | |||
99 | /** |
||
100 | * Get the full nname |
||
101 | * |
||
102 | * @return {String} fullName |
||
103 | */ |
||
104 | PlaceDisplayProperties.prototype.getFullName = function(){ |
||
105 | return this.fullName; |
||
106 | }; |
||
107 | |||
108 | /** |
||
109 | * Set the type |
||
110 | * |
||
111 | * @param {String} type |
||
112 | * @return {PlaceDisplayProperties} this |
||
113 | */ |
||
114 | PlaceDisplayProperties.prototype.setType = function(type){ |
||
115 | this.type = type; |
||
116 | return this; |
||
117 | }; |
||
118 | |||
119 | /** |
||
120 | * Get the type |
||
121 | * |
||
122 | * @return {String} type |
||
123 | */ |
||
124 | PlaceDisplayProperties.prototype.getType = function(){ |
||
125 | return this.type; |
||
126 | }; |
||
127 | |||
128 | /** |
||
129 | * Export the object as JSON |
||
130 | * |
||
131 | * @return {Object} JSON object |
||
132 | */ |
||
133 | PlaceDisplayProperties.prototype.toJSON = function(){ |
||
134 | return this._toJSON(Base, PlaceDisplayProperties.jsonProps); |
||
135 | }; |
||
136 | |||
137 | GedcomX.PlaceDisplayProperties = PlaceDisplayProperties; |
||
138 | |||
139 | }; |